package com.macro.mall.portal.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @Author：Minxiao-Hao
 * @Description:
 * @name：ThreadPoolConfig
 * @Date：2024/10/30 15:57
 */
@Configuration
public class ThreadPoolConfig {

    /**
     * 评论添加线程池
     * @return ThreadPoolTaskExecutor
     */
    @Bean(name = "commentAddThreadPool") // 告诉你这个线程池的名字
    public ThreadPoolTaskExecutor commentAddThreadPool() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(10); // 核心线程数
        executor.setMaxPoolSize(20); // 最大线程数
        executor.setQueueCapacity(100); // 队列容量
        executor.setKeepAliveSeconds(30); // 线程活动时间
        executor.setThreadNamePrefix("MyThreadPool-"); // 线程名前缀

        executor.setRejectedExecutionHandler(new java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy()); // 拒绝策略
        executor.initialize(); // 初始化
        return executor;
    }
    /**
     * 评论列表线程池
     * @return ThreadPoolTaskExecutor
     */
    @Bean(name = "commentListThreadPool") // 告诉你这个线程池的名字
    public ThreadPoolTaskExecutor commentListThreadPool() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(10); // 核心线程数
        executor.setMaxPoolSize(50); // 最大线程数
        executor.setQueueCapacity(400); // 队列容量
        executor.setKeepAliveSeconds(30); // 线程活动时间
        executor.setThreadNamePrefix("MyThreadPool-"); // 线程名前缀

        executor.setRejectedExecutionHandler(new java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy()); // 拒绝策略
        executor.initialize(); // 初始化
        return executor;
    }
}
